package com.yanqu.road.server.cmd.wingroom;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.wingroom.WingRoomProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.connect.CrossAgentLinkedControl;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.wingroom.CrossWingRoomMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import io.netty.channel.ChannelHandlerContext;

import java.util.List;

/**
 * @author ：zfr
 * @date ：2022/3/24 21:52
 */
@Cmd(code = CrossProtocol.C_WING_ROOM_GET_UNION_MEMBER_EVENT, desc = "获取跨服商会成员事件状态")
public class GetCrossUnionMemberEventStatusCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        WingRoomProto.GetUnionMemberEventReqCrossMsg reqCrossMsg = WingRoomProto.GetUnionMemberEventReqCrossMsg.parseFrom(packet.getBytes());
        List<WingRoomProto.WingRoomFriendTemp.Builder> unionMemberEventStatusList = CrossWingRoomMgr.getUserEventStatus(packet.getPlayerId(), reqCrossMsg.getMemberList());
        WingRoomProto.GetWingRoomFriendListRespMsg.Builder respMsg = WingRoomProto.GetWingRoomFriendListRespMsg.newBuilder();
        for (WingRoomProto.WingRoomFriendTemp wingRoomFriendTemp : reqCrossMsg.getFriendList()) {
            respMsg.addFriend(wingRoomFriendTemp);
        }
        for (WingRoomProto.WingRoomFriendTemp.Builder builder : unionMemberEventStatusList) {
            respMsg.addFriend(builder);
        }
        long serverId = CrossAgentLinkedControl.getLinkedClient(ctx).getServerId();
        YanQuMessage message = YanQuMessageUtils.buildMessage(ClientProtocol.U_WING_ROOM_GET_FRIEND_LIST, respMsg);
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), message);
    }
}
